package com.xunk.equipment.config;

import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class MqttConfig {

    @Autowired
    List<IMqttMessageListener> messageListeners;

    @Autowired
    private DnakeConfig dnakeConfig;

    @Bean("MQTT_126")
    public MQTTClient createMqttClient126() {
        MQTTClient client = new MQTTClient(dnakeConfig.getMqttHost(), dnakeConfig.getMqttUserName(), dnakeConfig.getMqttPassword());
        client.setMessageListeners(messageListeners);
        client.setType(2);
        client.start();
        return client;
    }

    @Bean("MQTT_83")
    public MQTTClient createMqttClient83() {
        MQTTClient client = new MQTTClient("tcp://112.126.81.83:1883", "12", "12");
        client.setMessageListeners(messageListeners);
        client.setType(1);
        client.start();
        return client;
    }
}
